/*
 * Unit.java
 * Copyright January 26, 2013 Erik Strelzoff
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.magelord.model;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.magelord.utils.JSONUtil;


public class Unit extends MLObject {
	public enum Type {
		BASIC,
		HERO,
		MAGELORD
		// City?
	}
	
	/**
	 * Unique ID.
	 */
	private int m_id;
	private String m_name;
	private Coordinates m_position;
	private Side m_side;
	private Type m_type;
	private int m_level;
	
	
//-- Type (Hero, infantry, etc.)
//-- Level
//-- Morale
//-- Mobility
//-- Combat properties
//--- Attack / defense modifiers etc.
//-- Abilities
//-- Effects (buffs / debuffs)
	
	public static void main(String[] args) throws ClassNotFoundException {
		GameState state = new GameState();
		Unit unit = new Unit();
		unit.setId(state.nextId());
		unit.setName("Erik");
		unit.setPosition(new Coordinates(1,5));
		unit.setType(Type.MAGELORD);
		unit.setLevel(999);
		
		Gson gson = JSONUtil.getGson();
		
		String jsonText = gson.toJson(unit);
		
		System.out.println(unit);
		System.out.println("----");
		System.out.println(jsonText);
		System.out.println("----");
		
		Unit new_unit = (Unit)MLObject.fromJson(jsonText, gson);
		
		System.out.println("Got new_unit: " + new_unit);
	}
	
	public Unit() {
		super();
	}
	
	public int getId() { return m_id; }
	public String getName() { return m_name; }
	public Coordinates getPosition() { return m_position; }
	public Side getSide() { return m_side; }
	public Type getType() { return m_type; }
	public int getLevel() { return m_level; }

	public void setId(int id) {
		m_id = id;
	}
	
	public void setName(String name) {
		m_name = name;
	}

	public void setPosition(Coordinates position) {
		m_position = position;
	}

	public void setSide(Side side) {
		m_side = side;
	}

	public void setType(Type type) {
		m_type = type;
	}

	public void setLevel(int level) {
		m_level = level;
	}
	
	public String toString() {
		return "Unit.  " + super.toString() + " Fields: " +
			" m_className: " + m_className +
			" m_id: " + m_id + 
			" m_name: " + m_name + 
			" m_position: " + m_position + 
			" m_side: " + m_side + 
			" m_type: " + m_type + 
			" m_level: " + m_level;
	}	
}
